import { Application } from 'egg';
import {
  loginRule
} from '../validate/wx/user';

/**
 * 用户相关的路由
 */
export default (app: Application) => {
  const { jwt } = app
  const { header } = app.middleware;
  return {
    'wx.login': {
      method: 'POST',
      path: '/xxm/user/login',
      options: {
        tags: ['wx-user'],
        description: '登录',
        handler: app.controller.wx.user.login,
        middlewares: [header()],
        validate: loginRule,
      },
    },
    'wx.update': {
      method: 'POST',
      path: '/xxm/user/update',
      options: {
        tags: ['wx-user-update'],
        description: '用户更新',
        handler: app.controller.wx.user.update,
        middlewares: [jwt],
        // validate: loginRule,
      },
    },
    'wx.userInfo': {
      method: 'GET',
      path: '/xxm/user/info',
      options: {
        tags: ['wx-user-info'],
        description: '用户信息',
        handler: app.controller.wx.user.userInfo,
        middlewares: [jwt],
        // validate: loginRule,
      },
    },
  };
};
